/* 
1. token存储的工具函数
2. 登陆用户存储的工具函数
*/

const TOKEN_KEY = 'token_key' // 存储token的key
const USER_KEY = 'user_key' // 存储登陆用户的key

// 保存token到localStorage
export const saveToken = (token) => localStorage.setItem(TOKEN_KEY, token)

// 从localStorage中读取token
export const getToken = () => localStorage.getItem(TOKEN_KEY)

// 删除localStorage中的token
export const removeToken = () => localStorage.removeItem(TOKEN_KEY)

// 保存user到sesssionStorage
export const saveUser = (user) => sessionStorage.setItem(USER_KEY, JSON.stringify(user))

// 从sesssionStorage中读取user
export const getUser = () => JSON.parse(sessionStorage.getItem(USER_KEY))

// 删除sesssionStorage中的user
export const removeUser = () => sessionStorage.removeItem(USER_KEY)